package com.yonyou.crm.sys.quartz.rmimpl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonyou.crm.common.page.entity.Page;
import com.yonyou.crm.sys.quartz.rmitf.IDispatchTaskRmService;
import com.yonyou.crm.sys.quartz.service.DispatchGroupBizService;
import com.yonyou.crm.sys.quartz.service.DispatchTaskBizService;
import com.yonyou.crm.sys.quartz.service.DispatchTaskLogBizService;
import com.yonyou.crm.sys.quartz.ventity.DispatchGroupVO;
import com.yonyou.crm.sys.quartz.ventity.DispatchTaskLogVO;
import com.yonyou.crm.sys.quartz.ventity.DispatchTaskVO;

@Service
public class DispatchTaskRmServiceImpl implements IDispatchTaskRmService {
	@SuppressWarnings("unused")
	private final Logger logger = LoggerFactory.getLogger(getClass());
	// 任务service
	@Autowired
	private DispatchTaskBizService bizTaskService;
	@Autowired
	private DispatchTaskLogBizService logService;
	@Autowired
	private DispatchGroupBizService groupService;

	/**
	 * 保存任务调度使用的，目的是为了集群使用 调度创建的任务
	 */
	@Override
	public DispatchTaskVO saveDispatchTaskVO(DispatchTaskVO vo) {
		return bizTaskService.saveDispatchTaskVO(vo);
	}

	/**
	 * 更新
	 */
	@Override
	public DispatchTaskVO updateDispatchTaskVO(DispatchTaskVO vo) {
		return bizTaskService.updateDispatchTaskVO(vo);
	}

	/**
	 * 根据id查询数据，即详情
	 */
	@Override
	public DispatchTaskVO getVOById(DispatchTaskVO vo, String id) {
		return bizTaskService.getVOById(id);
	}

	/**
	 * 获取任务列表
	 */
	@Override
	public Page<DispatchTaskVO> selectTask(Page<DispatchTaskVO> page,
			Map<String, Object> paramMap) {
		return bizTaskService.selectTask(page, paramMap);
	}

	/**
	 * 任务停用或启用
	 */
	public DispatchTaskVO updateEnableStatus(String id, Integer enableStatus) {
		DispatchTaskVO vo = bizTaskService.updateEnableStatus(id, enableStatus);
		return vo;
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public void deleteTask(String id,Page<DispatchTaskVO> page,
            Map<String, Object> paramMap) {
		bizTaskService.deleteTask(id);
		
	}

	public Map<String, Object> triggerTask(String id) {

		return bizTaskService.triggerTask(id);
	}

	@Override
	public DispatchTaskLogVO getTaskLogDetail(String id) {
		DispatchTaskLogVO logVO = logService.getVOById(id);
		String res = new String(logVO.getContent());
		logVO.setLogDetail(res);
		return logVO;

	}

	@Override
	public Page<DispatchGroupVO> getRefPage(Page<DispatchGroupVO> page,
			Map<String, Object> paraMap) {
		return groupService.getRefPage(page, paraMap);
	}

	@Override
	public List<DispatchGroupVO> getRefList(Map<String, Object> paraMap) {
		// TODO 自动生成的方法存根
		return groupService.getRefList(paraMap);
	}
}
